package IO;

import java.io.*;

/**
 * @author wuhan
 * @date 2019/10/9 17:19
 */
public class Buffered {
    public static void main(String[] args) {
//        FileWriter fw=new FileWriter("buf.txt");
//        BufferedWriter bufw=new BufferedWriter(fw);
//        bufw.write("davcd");
//        bufw.flush();
//        bufw.close();



//        FileReader fr=new FileReader("buf.txt");
//        BufferedReader bufr=new BufferedReader(fr);
//        String line=null;
//        StringBuffer sb=new StringBuffer();
//        while ((line=bufr.readLine())!=null){
//            sb.append(line+"\r\n");
//        }
//        System.out.println(sb.toString());

        BufferedReader bufferedReader=null;
        BufferedWriter bufferedWriter=null;


        try {
            bufferedReader=new BufferedReader(new FileReader("buf.txt"));
            bufferedWriter=new BufferedWriter(new FileWriter("Paste.txt"));
            String line;
            while (null != (line = bufferedReader.readLine())){
                bufferedWriter.write(line);
                bufferedWriter.newLine();
                bufferedWriter.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        finally {
            try {
                assert bufferedReader != null;
                bufferedReader.close();
                assert bufferedWriter != null;
                bufferedWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    }
}
class MyBufferedInputStream{
    private InputStream in;
    private byte[] buf=new byte[1024*4];
    private int pos=0,count=0;
    MyBufferedInputStream(InputStream in){
        this.in=in;
    }
    int myRead() throws IOException {
        if (count==0){
            count=in.read(buf);
            if (count<0)
                return -1;
            pos=0;
            byte b=buf[pos];
            pos++;
            count--;
            return b&255;
        } else if (count>0) {
            byte b=buf[pos];
            pos++;
            count--;
            return b&255;
        }
        return -1;
    }
    void myClose() throws IOException {
        in.close();
    }
}
